<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>商家管理</title>
	<%@ include file="/WEB-INF/pages/common/frameCommonJs.jsp"  %>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/adminManageService.js'></script>
	<script>
		var saveOrUpdateUrl = "";
		function savePro(){  
		    $('#fm').form('submit',{  
		        url:saveOrUpdateUrl,  
		        onSubmit: function(){  
		        	var retailPrice = $("#pro\\.retailPrice").val();
		        	var lowestPrice = $("#pro\\.lowestPrice").val();
		        	if((new Number(retailPrice)).valueOf() < (new Number(lowestPrice)).valueOf()){
		        		$.messager.alert("提示信息","最低售价不能大于零售价!",'warning');
		        		return false;
		        	}
		            return $(this).form('validate');  
		        },  
		        success: function(result){  
		            var result = eval('('+result+')');
		            var msg = result.companyName;
		            if($("#store\\.id").val()!=""){
		            	msg = msg + "修改成功";
		            }else{
		            	msg = msg + "新增成功";
		            }
		            if (result!=''){
		            	$.messager.show({title:"提示信息:",msg:msg,showType:'slide'});
		                $('#dlg').dialog('close');      // close the dialog  
		                $('#products').datagrid('reload');    // reload the user data  
		            } else {  
		                $.messager.show({  
		                    title: '新增成功',  
		                    msg: result.msg  
		                });  
		            }  
		        }  
		    });  
		}

		function toEditPro(){
			saveOrUpdateUrl = "<%=request.getContextPath()%>/adminmanage/addOrUpdateStore.action";
			var node=$("#products").datagrid("getSelected");
			if(node == null){
				$.messager.alert("提示信息:","请选择门店!");
				return;
			}
			$('#dlg').dialog('open').dialog('setTitle','修改门店');
			$('#dlg').form('clear');
			$("#store\\.id").val(node.id);
			$("#store\\.companyName").val(node.companyName);
			$("#store\\.bossName").val(node.bossName);
			$("#store\\.storeMobile").val(node.storeMobile);
			$("#store\\.storeEmail").val(node.storeEmail);
			$("#store\\.address").val(node.address);
			$("#store\\.contractTime").datebox("setValue",node.contractTime);
			$("#store\\.contractMonth").val(node.contractMonth);
			$("#store\\.note").val(node.note);
		}
		
		$(function(){
			$('#products').datagrid({
				nowrap: false,
				striped: true,
				url:'<%=request.getContextPath()%>/adminmanage/getALlStore.action',
				sortName: 'code',
				sortOrder: 'desc',
				remoteSort: false,
				idField:'code',
				singleSelect:true,
				title:'门店列表',
				columns:[[
					{field:'companyName',title:'门店名称',width:120},
					{field:'bossName',title:'店主姓名',width:120},
					{field:'storeMobile',title:'联系人手机',width:120},
					{field:'storeEmail',title:'联系邮箱',width:120,rowspan:2},
					{field:'address',title:'店铺地址',width:150,rowspan:2},
					{field:'createTime',title:'创建日期',width:80,rowspan:2,sortable:true},
					{field:'contractTime',title:'签约日期',width:80,rowspan:2,sortable:true},
					{field:'contractMonth',title:'签约时间',width:50,rowspan:2,
						formatter:function(value,row,index){
						    if(row.contractMonth != null){
						    	return row.contractMonth + "/月";
						    }else{
						    	return "";
						    }
							
						}
					},
					{field:'note',title:'备注',width:200,rowspan:2},
					{field:'action',title:'用户详情',width:50,
					  formatter:function(value,row,index){
		                   return '<a href="#" onclick="detail(' + row.id + ',' + '\'' + row.companyName + '\'' + ')">查询</a>'
               		  }
					}
				]],
				pageSize:15,  
                pageList:[5,10,15,20],  
                fitColumns: true,  
				pagination:true,
				rownumbers:true
			});
			$('#detailTable').datagrid({
				nowrap: false,
				striped: true,
				url:'<%=request.getContextPath()%>/adminmanage/getUserByStore.action',
				sortName: 'code',
				sortOrder: 'desc',
				remoteSort: false,
				idField:'code',
				singleSelect:true,
				columns:[[
					{field:'loginName',title:'登录名',width:120},
					{field:'name',title:'姓名',width:120},
					{field:'role',title:'角色',width:120,
						formatter:function(value,row,index){
							if(row.isAdmin=="1"){
								return "<font color='blue'>老板</font>";
							}
							else if(row.isAdmin=="2"){
								return "<font color='red'>管理员</font>";
							}else {
								return "员工";
							}
						}
					},
					{field:'storeName',title:'所属门店',width:120},
					{field:'createTime',title:'创建时间',width:150,rowspan:2,sortable:true},
					{field:'loginTime',title:'最后登录时间',width:100,rowspan:2,sortable:true},
					{field:'note',title:'备注',width:100,rowspan:2}
				]],
				pageSize:15,  
                pageList:[5,10,15,20],  
                fitColumns: true,  
				pagination:true,
				rownumbers:true
			});
		}); 
		function toAddPro(){
			saveOrUpdateUrl = "<%=request.getContextPath()%>/adminmanage/addOrUpdateStore.action";
			$('#dlg').dialog('open').dialog('setTitle','新增商家');
			$('#dlg').form('clear');
		}
		function toDelPro(){
			var node = $('#products').datagrid('getSelected');
			adminManageService.valDelStore(node.id,function(data){
				if(data=="1"){
					$.messager.alert("提示信息","该门店下已有用户信息，不能删除!",'warning');
					return;
				}
				$.messager.confirm('删除门店信息', '确认删除[' + node.companyName + ']吗?', function(r){
					if(r){
						$.ajax({
							type:"post",
							data:"storeid=" + node.id,
							url:"<%=request.getContextPath()%>/adminmanage/delStore.action",
							success:function(result){
								var data = eval('(' + result + ')');
								$.messager.show({title:"提示信息",msg: node.companyName + "删除成功",showType:'slide'});
								$('#products').datagrid('reload');
							}
						});
						
					}
				});
			});
		}
		
		
		function clearData(){
			$('#searchForm').form('clear');
		}
		
		jQuery(function(){
			
			jQuery('a[name=query]').click(function(){
				var name = $('#name').val();
				$('#products').datagrid('reload',{name:name});
			});
		});
		
		function detail(id,name){
			var title = "门店[" + name + "]的用户详情";
			// 详细内容
	   		$('#detailDlg').dialog('open').dialog('setTitle',title); 
	   		$('#detailTable').datagrid('reload',{'storeid':id});
		}
	</script>
</head> 
<body class="easyui-layout" >
	<!-- 
	<h2>商品列表</h2>
	<div class="demo-info" style="margin-bottom:10px">
		<div class="demo-tip icon-tip"></div>
		<div>Click the row to start editing.</div>
	</div>
	 -->
	<div region="center" title="门店信息管理" style="overflow:hidden;">
	<div id="tb" class="datagrid-toolbar">  
	    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:toAddPro()">新增</a>  
	    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="javascript:toEditPro();">修改</a>  
	    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:toDelPro()">删除</a>
	</div>
	<form id="searchForm" method="post">
	<table style="font-size:12px; background:#fafafa; padding:10px;" border="0">
		<tr>
			<td>门店名称
				<input type="text" id="name" name="name" class="easyui-validatebox"  value="${name}" />
				<!-- 
				<input type="hidden" id="pcId" name="pcId" value="" />
				 -->
			</td>
			<td>
				<a href="#" class="easyui-linkbutton" name="query">查询</a>
 				<a href="#" class="easyui-linkbutton" onclick="clearData()">重置</a>
			</td>
		</tr>
	</table>
	</form>
	<table id="products"></table>
	</div>
	<div id="detailDlg" class="easyui-dialog" style="width:920px;height:518px;"  
        closed="true" buttons="#dlg-buttons"> 
        <table id="detailTable"></table>
	</div>
	<div id="dlg" class="easyui-dialog" style="width:400px"  
        closed="true" buttons="#dlg-buttons" resizable="true">  
    <form id="fm" method="post">
    <center>
    <table border="0">
    	<input id="store.id" name="store.id" type="hidden" />  
        	<tr>
        		<td>门店名称：</td>
        		 <td>
        		 	<input id="store.companyName" name="store.companyName" class="easyui-validatebox" required="true" size="30" maxlength="50" />
        		 </td>  
        	</tr>
        	<tr>
        		<td>店主姓名：</td>
            	<td>
            		<input id="store.bossName" name="store.bossName" class="easyui-validatebox" maxlength="20" required="true" />
            	</td>
            </tr>
            <tr>
        		<td>店主手机：</td>
            	<td>
            		<input id="store.storeMobile" name="store.storeMobile" required="true"/>
            	</td>
            </tr>
            <tr>
        		<td>联系邮箱：</td>
            	<td>
            		<input id="store.storeEmail" name="store.storeEmail"  />
            	</td>
            </tr>
            <tr>
            	<td>店铺地址：</td>
            	<td>
            		<input id="store.address" name="store.address" class="easyui-validatebox" maxlength="20" required="true" />  
            	</td>
            </tr>
            <tr>
            	<td>签约日期：</td>
            	<td>
            		<input id="store.contractTime" name="store.contractTime" maxlength="20" class="easyui-datebox" />
            	</td>
            </tr>
            <tr>
            	<td>
            		签约多久：
            	</td>
            	<td>
            		<input id="store.contractMonth" name="store.contractMonth" class="easyui-validatebox" maxlength="20"  size="3" /> / 月
            	</td>
            </tr> 
            <tr>
            	<td>描述：</td>
            	<td>
           			<textarea id="store.note" name="store.note" class="easyui-validatebox" rows="4" cols="25" maxlength="200"></textarea>
           		</td>
           	</tr>
        </table>
        </center>
        </form> 
	</div>
	<div id="dlg-buttons">  
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="savePro()">保存</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>  
	</div>
</body>
</html>
